//
//  BinaryClockAppDelegate.m
//  BinaryClock
//
//  Created by Peter Elst on 7/18/08.
//  Copyright Peter Elst 2008. All rights reserved.
//

#import "BinaryClockAppDelegate.h"
#import "BinaryClockViewController.h"

@implementation BinaryClockViewController

@synthesize hours1;
@synthesize hours2;
@synthesize minutes1;
@synthesize minutes2;
@synthesize seconds1;
@synthesize seconds2;
@synthesize clockTimer;

- (void)viewDidLoad {
	[super viewDidLoad];
	[self.view setBackgroundColor: [UIColor blackColor]];
	clockTimer = [NSTimer scheduledTimerWithTimeInterval:1 
						  target:self
						  selector:@selector(getCurrentTime)
						  userInfo:nil 
						  repeats: YES];
	[self getCurrentTime];
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	for (UITouch *touch in touches){
		if(touch.tapCount == 2) {
			[(BinaryClockAppDelegate*)[[UIApplication sharedApplication] delegate] toggleView];
		}
	}
}


- (void)getCurrentTime {
	NSDate *now = [NSDate date];
	NSString *timestamp = [now description];
	NSString *currentHour1 = [timestamp substringWithRange:NSMakeRange(11,1)];
	NSString *currentHour2 = [timestamp substringWithRange:NSMakeRange(12,1)];
	NSString *currentMinute1 = [timestamp substringWithRange:NSMakeRange(14,1)];
	NSString *currentMinute2 = [timestamp substringWithRange:NSMakeRange(15,1)];
	NSString *currentSecond1 = [timestamp substringWithRange:NSMakeRange(17,1)];
	NSString *currentSecond2 = [timestamp substringWithRange:NSMakeRange(18,1)];
	[hours1 setImage: [UIImage imageNamed: [currentHour1 stringByAppendingString: @"-2.png"]]];
	[hours2 setImage: [UIImage imageNamed: [currentHour2 stringByAppendingString: @".png"]]];
	[minutes1 setImage: [UIImage imageNamed: [currentMinute1 stringByAppendingString: @"-3.png"]]];
	[minutes2 setImage: [UIImage imageNamed: [currentMinute2 stringByAppendingString: @".png"]]];
	[seconds1 setImage: [UIImage imageNamed: [currentSecond1 stringByAppendingString: @"-3.png"]]];
	[seconds2 setImage: [UIImage imageNamed: [currentSecond2 stringByAppendingString: @".png"]]];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return YES;
}


- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning];
}


- (void)dealloc {
	[super dealloc];
}

@end
